/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.V050;
import queenb.web.crm.store.CustomerStore;
import queenb.web.inteface.V500Inf;
import queenb.web.store.V050Store;
import queenb.web.store.V500Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.ContextUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class V050Controller extends QueenbController {

    private List<V050> listV050N;
    private V050Store v050Store;
    private V500Store v500Store;
    private V500Inf v050inf;
    private int pv050;
    private String v051;
    private String v052;
    private String v065 = "OP";// Trang Thai Tour
    private String vv051;
    private String vv069;
    private String vv070;
    private String vv071;
    private int vn072;
    private String vv052;
    private int fk100;
    private int fn100;
    private int vn053;// so nguoi toi da
    private int vn054;// so nguoi tham gia
    private double vn055;// Giá Tour
    private Date vd073;// ngay kho ihanh
    private Date vd074;// ngay het thuc
    private int vn079; // INT OR OUT
    private int fs400;// san oham TOur
    private int fc475;// Quy trinh VISA
    private List<SelectItem> cbbFS400 = (List<SelectItem>) new ArrayList<SelectItem>();
    private List<SelectItem> cbbFC475 = (List<SelectItem>) new ArrayList<SelectItem>();

    public V050Controller() {
        getKapiMenu().setAdmin(false);
        getKapiMenu().setMainmenu1("m14"); // Hien thi Menu nao dc chon
        v050Store = new V050Store();
        v500Store = new V500Store();
        Object action = getRequest().getParameter("action");
        if (action != null) {
            if (action.equals("updateStatus")) {
                Object idObject1 = getRequest().getParameter("FV050");
                Object idObject2 = getRequest().getParameter("VV065");
                if (idObject1 != null && idObject2 != null) {
                    updateStatusForTuor(Util.parseInt(idObject1), idObject2.toString());
                }
            }
        }
        try {
            Object idObject1 = getRequest().getParameter("idedit");
            if (idObject1 != null) {
                pv050 = Util.parseInt(idObject1.toString());
                getListByIdV050(pv050);
            }
        } catch (Exception e) {
        }
        try {
            Object idObject = getRequest().getParameter("id");
            if (idObject != null) {
                pv050 = Util.parseInt(idObject.toString());
            }
        } catch (Exception e) {
        }
        try {
            Object idObject1 = getRequest().getParameter("id");
            if (idObject1 != null) {
                fn100 = Util.parseInt(idObject1.toString());

            }
        } catch (Exception e) {
        }

        try {
            Object idObject2 = getRequest().getParameter("id");
            if (idObject2 != null) {
                fk100 = Util.parseInt(idObject2.toString());
                System.out.println("--------------------- TUNG ------" + fn100);
            }
        } catch (Exception e) {
        }
    }

    public void updateStatusForTuor(int fv050, String VV065) {
        try {
            CustomerStore store = new CustomerStore();

            int coun = store.updateColumnN100(null, "V050", "VV065", VV065, "PV050", fv050, getLogin().getUserName());
            if (coun > 0) {
                //   showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                //  showGlobalReport(true, getResourceString("datasuccessfail"));
            }
        } catch (Exception e) {
        }
    }

    public List<V050> getListAllV050ByID() {

        try {

            if (listV050N == null || listV050N.size() == 0) {

                listV050N = v050Store.listV050(7, 99, 0, 0, getLogin().getUserName());
                System.out.println("00------> size CMND" + listV050N.size());
            }
            return listV050N;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }

    }

// tao tour moi trong lít Tour theo quy trinh VISA
    public void stdv_tools_inserttabv050new() {
        try {
            String dateStart = ContextUtil.getRequestParameter("from");
            if (!dateStart.equals("")) {
                vd073 = Util.parseDate(dateStart, "dd/MM/yyyy");
            } else {
                vd073 = null;
            }
            String dateend = ContextUtil.getRequestParameter("to");
            if (!dateend.equals("")) {
                vd074 = Util.parseDate(dateend, "dd/MM/yyyy");
            } else {
                vd074 = null;
            }
            V050Store v050Store = new V050Store();
            int count = 0;
            System.out.println("------THAM SO------" + pv050 + "," + v051 + "," + vv052 + "," + vn053 + "," + vn054 + "," + vn055 + ", " + Util.UnUnicode(vv052) + "," + Util.toSQLDate(vd073) + "," + Util.toSQLDate(vd074) + "," + vn079 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + fs400 + "," + fc475 + "," + fk100 + "," + getLogin().getUserName());
            count = v050Store.stdv_tools_inserttabv050new(pv050, v051, vv052, vn053, vn054, vn055, Util.UnUnicode(vv052), Util.toSQLDate(vd073), Util.toSQLDate(vd074), vn079, getLogin().getModule(), getLogin().getCompanyNo(), fs400, fc475, fk100, getLogin().getUserName());
            System.out.println("-------------COUNT---" + count);
            if (count >= 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
                sendRedirectUrlTab("listTour.jsp");
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
                sendRedirectUrlTab("listTour.jsp");
            }
        } catch (Exception e) {
        }
    }

    public void updateByV050() {
        try {

            System.out.println("v500Store.updateV050By(" + pv050 + "," + this.getLogin().getModule() + "," + getLogin().getCompanyNo() + ","
                    + 0 + "," + vv051 + "," + vv052 + "," + 0 + "," + 0 + ","
                    + Util.convertStringToDouble("0") + "," + 0 + "," + 0 + "," + Util.convertStringToDouble("0") + "," + 0 + ","
                    + 0 + "," + Util.convertStringToDouble("0") + "," + 0 + "," + 0 + "," + Util.convertStringToDouble("0") + "," + this.v065 + "," + "S" + "," + vv069 + "," + vv070 + "," + getLogin().getUserName());
//             int update = v050Store.updateV050By(pv050, this.getLogin().getModule(), getLogin().getCompanyNo(),
//                            0, this.vv051, this.vv052, 0, 0,
//                            0, 0,0, 0, 0,
//                            0,0, 0, 0, 0,this.v065, "S", getLogin().getUserName());
            int update = v500Store.updateV050By(pv050, this.getLogin().getModule(), getLogin().getCompanyNo(),
                    0, vv051, vv052, 0, 0,
                    Util.convertStringToDouble("0"), 0, 0, Util.convertStringToDouble("0"), 0,
                    0, Util.convertStringToDouble("0"), 0, 0, Util.convertStringToDouble("0"), this.v065, "S", vv069, vv070, getVv071(), getVn072(), getLogin().getUserName());
            if (update >= 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }
            sendRedirect("managerSale.jsp");
        } catch (Exception e) {
            showGlobalReport(true, getResourceString("datasuccessfail"));
            sendRedirect("managerSale.jsp");
        }
    }

    public List<V050> getListAllV050() {

        try {

            if (listV050N == null || listV050N.size() == 0) {
                v050Store = new V050Store();
                listV050N = v050Store.listV050All(getLogin().getModule(), getLogin().getCompanyNo(), 0, "S", getLogin().getUserName());
                System.out.println("NSTTTTTTTTTTTTTTTTTTT" + listV050N.size());
            }
            return listV050N;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }
    }
    // Lịch sử Tour khách hàng

    public List<V050> getListAllV050KH() {

        try {

            if (listV050N == null || listV050N.size() == 0) {
                v050Store = new V050Store();
                if (SessionProvider.getSessionMapValue("PN100HD") != null) {
                    fn100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
                }
                listV050N = v050Store.getListAllV030KH(getLogin().getModule(), getLogin().getCompanyNo(), fn100, getLogin().getUserName());
                System.out.println("NSTTTTTTTTTTTTTTTTTTT" + listV050N.size());
            }
            return listV050N;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }
    }
    // Lịch sử Tour công ty

    public List<V050> getListAllV050CT() {

        try {

            if (listV050N == null || listV050N.size() == 0) {
                v050Store = new V050Store();
                if (SessionProvider.getSessionMapValue("PN100HD") != null) {
                    fk100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
                }
                listV050N = v050Store.getListAllV050CT(getLogin().getModule(), getLogin().getCompanyNo(), fk100, getLogin().getUserName());
                System.out.println("NSTTTTTTTTTTTTTTTTTTT" + listV050N.size());
            }
            return listV050N;
        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }
    }

    public void getListByIdV050(int id) {
        try {
            List<V050> listV050 = v050Store.listV050All(getLogin().getModule(), getLogin().getCompanyNo(), id, "S", getLogin().getUserName());
            if (listV050 != null && listV050.size() > 0) {
                for (int i = 0; i < listV050.size(); i++) {
                    if (listV050.get(i).getFv050() == id) {
                        this.pv050 = listV050.get(i).getFv050();
                        this.v052 = listV050.get(i).getVv052();
                        this.v065 = listV050.get(i).getVv065();
                        this.vv051 = listV050.get(i).getVv051();
                        this.vv052 = listV050.get(i).getVv052();
                        this.vv069 = listV050.get(i).getVv069();
                        this.vv070 = listV050.get(i).getVv070();
                        this.vv071 = listV050.get(i).getVv071();
                    }
                }
            }
        } catch (Exception e) {
        }
    }

    /**
     * @return the pv050
     */
    public int getPv050() {
        return pv050;
    }

    /**
     * @param pv050 the pv050 to set
     */
    public void setPv050(int pv050) {
        this.pv050 = pv050;
    }

    /**
     * @return the v051
     */
    public String getV051() {
        return v051;
    }

    /**
     * @param v051 the v051 to set
     */
    public void setV051(String v051) {
        this.v051 = v051;
    }

    /**
     * @return the v052
     */
    public String getV052() {
        return v052;
    }

    /**
     * @param v052 the v052 to set
     */
    public void setV052(String v052) {
        this.v052 = v052;
    }

    /**
     * @return the v065
     */
    public String getV065() {
        return v065;
    }

    /**
     * @param v065 the v065 to set
     */
    public void setV065(String v065) {
        this.v065 = v065;
    }

    /**
     * @return the vv051
     */
    public String getVv051() {
        return vv051;
    }

    /**
     * @param vv051 the vv051 to set
     */
    public void setVv051(String vv051) {
        this.vv051 = vv051;
    }

    /**
     * @return the vv069
     */
    public String getVv069() {
        return vv069;
    }

    /**
     * @param vv069 the vv069 to set
     */
    public void setVv069(String vv069) {
        this.vv069 = vv069;
    }

    /**
     * @return the vv070
     */
    public String getVv070() {
        return vv070;
    }

    /**
     * @param vv070 the vv070 to set
     */
    public void setVv070(String vv070) {
        this.vv070 = vv070;
    }

    /**
     * @return the vv052
     */
    public String getVv052() {
        return vv052;
    }

    /**
     * @param vv052 the vv052 to set
     */
    public void setVv052(String vv052) {
        this.vv052 = vv052;
    }

    /**
     * @return the vv071
     */
    public String getVv071() {
        return vv071;
    }

    /**
     * @param vv071 the vv071 to set
     */
    public void setVv071(String vv071) {
        this.vv071 = vv071;
    }

    /**
     * @return the v050inf
     */
    public V500Inf getV050inf() {
        return v050inf;
    }

    /**
     * @param v050inf the v050inf to set
     */
    public void setV050inf(V500Inf v050inf) {
        this.v050inf = v050inf;
    }

    /**
     * @return the fk100
     */
    public int getFk100() {
        return fk100;
    }

    /**
     * @param fk100 the fk100 to set
     */
    public void setFk100(int fk100) {
        this.fk100 = fk100;
    }

    /**
     * @return the fn100
     */
    public int getFn100() {
        return fn100;
    }

    /**
     * @param fn100 the fn100 to set
     */
    public void setFn100(int fn100) {
        this.fn100 = fn100;
    }

    /**
     * @return the vn072
     */
    public int getVn072() {
        return vn072;
    }

    /**
     * @param vn072 the vn072 to set
     */
    public void setVn072(int vn072) {
        this.vn072 = vn072;
    }

    /**
     * @return the vn053
     */
    public int getVn053() {
        return vn053;
    }

    /**
     * @param vn053 the vn053 to set
     */
    public void setVn053(int vn053) {
        this.vn053 = vn053;
    }

    /**
     * @return the vn054
     */
    public int getVn054() {
        return vn054;
    }

    /**
     * @param vn054 the vn054 to set
     */
    public void setVn054(int vn054) {
        this.vn054 = vn054;
    }

    /**
     * @return the vn055
     */
    public double getVn055() {
        return vn055;
    }

    /**
     * @param vn055 the vn055 to set
     */
    public void setVn055(double vn055) {
        this.vn055 = vn055;
    }

    /**
     * @return the vd073
     */
    public Date getVd073() {
        return vd073;
    }

    /**
     * @param vd073 the vd073 to set
     */
    public void setVd073(Date vd073) {
        this.vd073 = vd073;
    }

    /**
     * @return the vd074
     */
    public Date getVd074() {
        return vd074;
    }

    /**
     * @param vd074 the vd074 to set
     */
    public void setVd074(Date vd074) {
        this.vd074 = vd074;
    }

    /**
     * @return the vn079
     */
    public int getVn079() {
        return vn079;
    }

    /**
     * @param vn079 the vn079 to set
     */
    public void setVn079(int vn079) {
        this.vn079 = vn079;
    }

    /**
     * @return the fs400
     */
    public int getFs400() {
        return fs400;
    }

    /**
     * @param fs400 the fs400 to set
     */
    public void setFs400(int fs400) {
        this.fs400 = fs400;
    }

    /**
     * @return the fc475
     */
    public int getFc475() {
        return fc475;
    }

    /**
     * @param fc475 the fc475 to set
     */
    public void setFc475(int fc475) {
        this.fc475 = fc475;
    }

    /**
     * @return the cbbFS400
     */
    public List<SelectItem> getCbbFS400() {
        try {
            ComboboxUtil cbb = new ComboboxUtil();
            cbbFS400 = cbb.getListCombS400();
        } catch (Exception e) {
        }
        return cbbFS400;
    }

    /**
     * @param cbbFS400 the cbbFS400 to set
     */
    public void setCbbFS400(List<SelectItem> cbbFS400) {
        this.cbbFS400 = cbbFS400;
    }

    /**
     * @return the cbbFC475
     */
    public List<SelectItem> getCbbFC475() {
        try {
            ComboboxUtil cbb = new ComboboxUtil();
            cbbFC475 = cbb.getSelectedC475Comb();
        } catch (Exception e) {
        }
        return cbbFC475;
    }

    /**
     * @param cbbFC475 the cbbFC475 to set
     */
    public void setCbbFC475(List<SelectItem> cbbFC475) {
        this.cbbFC475 = cbbFC475;
    }
}
